package org.gvp.record.repository.impl;

import lombok.RequiredArgsConstructor;

import org.gvp.record.dto.ReportUpdate;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.gvp.record.repository.ReportRepository;
import org.gvp.record.mapper.ReportMapper;
import org.gvp.record.pojo.Report;
import java.util.List;
/**
 * 报销单表 数据层接口实现类
 */
@Repository
@RequiredArgsConstructor
public class ReportRepositoryImpl implements ReportRepository {
    private final ReportMapper reportMapper;

    @Override
    public Integer modifyAmountAndCount(ReportUpdate update) {
        return this.reportMapper.update(Wrappers.<Report>lambdaUpdate()
                .eq(Report::getId, update.getReportId())
                .set(Report::getTotalAmount, update.getAmount())
                .set(Report::getTotalCount, update.getCount()));
    }

    @Override
    public int append(Report pojo) {
        return this.reportMapper.insert(pojo);
    }

    @Override
    public int modify(Report pojo) {
        return this.reportMapper.updateById(pojo);
    }

    @Override
    public int cancel(Integer id) {
        return this.reportMapper.deleteById(id);
    }

    @Override
    public Report searchById(Integer id) {
        return this.reportMapper.selectById(id);
    }

    @Override
    public List<Report> searchList() {
        return this.reportMapper.selectList(null);
    }

    @Override
    public Long searchCount(String field) {
        return this.reportMapper.selectCount(null);
    }

    @Override
    public List<Report> searchLimit(int start, int end) {
        return this.reportMapper.selectList(Wrappers.<Report>lambdaQuery()
                .last("LIMIT %d,%d".formatted(start,end))
                .orderByDesc(Report::getOrder)
                .orderByAsc(Report::getId)
        );
    }

}
